<template>
  <!-- Banner -->
  <Banner :layout="layout" />

  <div class="container md:w-screen-xl m-auto">
    <div class="flex flex-col" v-if="app">
      <Breadcrumb :data="form" :title="`应用详情`" />
      <div class="page-main w-full bg-white rounded-lg">
        <div class="p-4 leading-7">
          <div class="goods-info flex">
            <el-avatar :src="app.appIcon" class="mr-2" size="large" />
            <div class="flex flex-col ml-2">
              <div class="text-lg">{{ app.appName }}</div>
              <div class="text-gray-400 w-screen-lg">{{ app.comments }}</div>
              <div>应用ID: <span class="text-blue-500">{{ app.appId }}</span></div>
              <div>后台演示: <span class="text-blue-500">{{ app.adminUrl }}</span></div>
              <div>前端演示: <span class="text-blue-500">{{ app.appUrl }}</span></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <!-- 空白页 -->
  <div class="mt-[60px]" v-if="!app">
    <el-empty description="404 页面不存在"></el-empty>
  </div>

</template>
<script setup lang="ts">
import { Search } from '@element-plus/icons-vue'
import type {ApiResult, PageResult} from "~/api";
import {useServerRequest} from "~/composables/useServerRequest";
import {useWebsite} from "~/composables/configState";
import type {Navigation} from "~/api/cms/navigation/model";
import {getIdByParam, getPath} from "~/utils/common";
import type {Company, CompanyParam} from "~/api/system/company/model";
import {navigateTo} from "#imports";
import Breadcrumb from "~/components/Breadcrumb.vue";
import type {App} from "~/api/oa/app/model";

const route = useRoute();

// 页面信息
const runtimeConfig = useRuntimeConfig();
const resultText = ref('');
const layout = ref<any>();

// 获取状态
const form = ref<Navigation>();
const website = useWebsite();
const app = ref<App>()

// 搜索表单
const where = reactive<CompanyParam>({
  keywords: ''
});

const navTo = (item: Company) => {
  navigateTo(`/market/${item.companyId}`)
}

// 请求数据
const reload = async () => {

  const { data: nav } = await useServerRequest<ApiResult<Navigation>>('/cms/cms-navigation/getNavigationByPath',{query: {path: getPath()}})
  if(nav.value?.data){
    form.value = nav.value?.data;
  }
  // 页面布局
  if(form.value?.layout){
    layout.value = JSON.parse(form.value?.layout)
  }
  useHead({
    title: `搜索结果 - ${website.value.websiteName}`,
    bodyAttrs: {
      class: "page-container",
    }
  });
  await handleClick()
}

// 搜索结果
const handleClick = async () => {
  const {data: response} = await useServerRequest<ApiResult<App>>(`/oa/oa-app/${getIdByParam()}`,{baseURL: runtimeConfig.public.apiServer})
  if(response.value?.data){
    if (response.value.data) {
      app.value = response.value.data
    }
    if(!response.value){
      resultText.value = '暂无相关结果'
    }
  }
}

watch(
    () => route,
    () => {
      reload();
    },
    { immediate: true }
);

</script>
